import { Component, PropTypes } from '@didi/teddy-immutable'
const { string, bool, func, object } = PropTypes

const noop = () => {}
class FormItem extends Component {
  static propTypes = {
    type: string, // 可能值为 input、picker、captcha
    title: string, // label 标题
    val: string, // Input 和 captcha 的时候使用该值
    src: string, // captch 验证码时，图片地址
    onInput: func, // Input 和 captcha 时，输入值回调
    showArrow: bool,
    name: string,  // input 名字
    inputType: string, // input 类型
    maxlength: string,
    isInputShow: bool,
    onTap: func
  }

  static defaultProps = {
    type: 'input',
    showArrow: false,
    title: '',
    val: '', // Input 和 captcha 的时候使用该值
    src: '', // captch 验证码时，图片地址
    onInput: noop, // Input 和 captcha 时，输入值回调
    onCaptchaTap: noop,
    name: '',
    inputType: 'number',
    isInputShow: true,
    maxlength: '1000',
    onTap: noop
  }

  state = {
    isInput: false,
    isPicker: false,
    isCaptcha: false
  }

  onLoad() {
    const stateObj = {}
    switch (this.props.type) {
      case 'input':
        stateObj.isInput = true
        break
      case 'picker':
        stateObj.isPicker = true
        break
      case 'captcha':
        stateObj.isCaptcha = true
        break
      default:
        stateObj.isInput = true
    }

    this.setState(stateObj)
  }

  onInput(e) {
    this.props.onInput(e)
  }

  onPickerTap(e) {
    this.props.onTap(e)
  }

  // 点击验证码
  onCaptchaTap(e) {
    this.props.onCaptchaTap(e)
  }
}

export default FormItem